/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

#ifndef _CONTROLPOINTS_H
#define _CONTROLPOINTS_H

#include <iostream>
#include <limits>
#include <QPointF>
#include <QMatrix>

#include <cmath>

#include "../gType.h"
#include "../transformation.h"

class controlPoints{

	private:
		static const float GAP = 0.001;
		static const int POINT_SIZE = 5;
		static const float MINIMAL_MOVE_DISTANCE = 2 * 2;
		//pixels
		static const int PRIMITIVE_DISTANCE = 2;
		
		gObjectContainer *container;
		QMatrix *matrix;
		gObject *activeGObject;
		gTypeGo *activeGTypeGo;
		QPointF activePoint;
		gObject *clickedGObject;
		gTypeGo *clickedGTypeGo;
		gObject *doubleClickedGObject;
		QPointF clickedPoint;
		QPointF buffPoint;
		bool press;
		bool wasClicked;
		
		void addPoint(QPointF &);
		bool isIn(const QPointF &, const QPointF &) const;
		float distance(QPointF &, QPointF &);
		float getDistance(QPointF &, QPointF &) const;
		float getHigh(QPointF &, QPointF &, QPointF &) const;
		bool circlePrimitive(QPointF &, QPointF &, QPointF &, QPointF &, int) const;
		bool primitiveIntersect(gTypeGo &, gTypeGo &, QPointF &) const;
	
	public slots:
		void drawAreaMark();
		void drawAreaFocus();
		
	public:
		controlPoints(gObjectContainer *);
		
		bool intersect(QPointF &);
		void setMatrix(QMatrix *);
		bool isActive() const;
		void clicked(QPointF &);
		void clicked(gObject *, gTypeGo *);
		bool isClicked() const;
		void doubleClicked(QPointF &);
		void doubleClicked(gObject *);
		bool isDoubleClicked() const;
		void pressed(QPointF &);
		bool isPressed();
		void setMiddle();
		bool isMiddle();
		bool isWasClicked();
		void update();
		
		gObject *getActiveGObject() const;
		gTypeGo *getActiveGTypeGo() const;
		const QPointF &getActivePoint() const;
		gObject *getClickedGObject() const;
		gObject *getDoubleClickedGObject() const;
		gTypeGo *getClickedGTypeGo() const;
		const QPointF &getClickedPoint() const;
		const QPointF &getPressedPoint() const;

};

#endif
